// import {sites, setting} from './dexie'
import axios from 'axios'

const yq = {
    xmlConfig: { // XML 转 JSON 配置
        trimValues: true,
        textNodeName: '_t',
        ignoreAttributes: false,
        attributeNamePrefix: '_',
        parseAttributeValue: true
    },
    getPlist(bvid) {
        return new Promise((resolve, reject) => {
            axios.get('https://api.bilibili.com/x/player/pagelist?bvid=' + bvid).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        })
    },
    getVedioUrl(aid, cid) {
        let url = 'https://api.bilibili.com/x/player/playurl?cid=' + cid + '&bvid=' + aid + '&platform=html5&high_quality=112';
        return new Promise((resolve, reject) => {
            axios.get(url).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        })
    },
    getVedioUrl2(aid, cid) {
        const params = {
            aid,
            cid,
            high_quality: 112,
        };
        return new Promise((resolve, reject) => {
            axios.get("https://api.bilibili.com/x/player/playurl", {
                params,
            }).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        })
    },
    searchList(url, word, page) {
        url = `${url}?ac=videolist&wd=${encodeURI(word)}`
        return new Promise((resolve, reject) => {
            axios.get(url).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        })
    },
    getSiteClass(url) {
        url = `${url}?ac=list`
        return new Promise((resolve, reject) => {
            axios.get(url).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        })
    },
    getDetail(url, id) {
        url = `${url}?ac=videolist&ids=${id}`
        return new Promise((resolve, reject) => {
            axios.get(url).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        })
    },
}
export default yq
